#include "SDL_image.h"
#include <assert.h>

void InitialisationImage (Image * i)
{
	(*i).imgdecor = (SDL_Surface**) malloc (21*sizeof (SDL_Surface*));
	(*i).imgdecor[0] = SDL_LoadBMP ("data/plaine.bmp");
	(*i).imgdecor[1] = SDL_LoadBMP ("data/arbre.bmp");
	(*i).imgdecor[2] = SDL_LoadBMP ("data/mer.bmp");
	(*i).imgdecor[3] = SDL_LoadBMP ("data/chantiercabane.bmp");
	(*i).imgdecor[4] = SDL_LoadBMP ("data/cabane.bmp");
	(*i).imgdecor[5] = SDL_LoadBMP ("data/mer2.bmp");
	(*i).imgdecor[6] = SDL_LoadBMP ("data/mer3.bmp");
	(*i).imgdecor[7] = SDL_LoadBMP ("data/mer4.bmp");
	(*i).imgdecor[8] = SDL_LoadBMP ("data/mer5.bmp");
	(*i).imgdecor[9] = SDL_LoadBMP ("data/caillou.bmp");
	(*i).imgdecor[10] = SDL_LoadBMP ("data/arbrevrai2.bmp");
	(*i).imgdecor[11] = SDL_LoadBMP ("data/arbrevrai3.bmp");
	(*i).imgdecor[12] = SDL_LoadBMP ("data/arbrevrai4.bmp");
	(*i).imgdecor[13] = SDL_LoadBMP ("data/arbrevrai5.bmp");
	(*i).imgdecor[14] = SDL_LoadBMP ("data/arbrevrai6.bmp");
	(*i).imgdecor[15] = SDL_LoadBMP ("data/arbrevrai7.bmp");
	(*i).imgdecor[16] = SDL_LoadBMP ("data/peche1.bmp");
	(*i).imgdecor[17] = SDL_LoadBMP ("data/peche2.bmp");
	(*i).imgdecor[18] = SDL_LoadBMP ("data/peche3.bmp");
	(*i).imgdecor[19] = SDL_LoadBMP ("data/Cabanerouge.bmp");
	(*i).imgdecor[20] = SDL_LoadBMP ("data/Cabanebleu.bmp");
	
	(*i).imgdecor2 = (SDL_Surface**) malloc (7*sizeof (SDL_Surface*));
	(*i).imgdecor2[0] = SDL_LoadBMP ("data/pplaine.bmp");
	(*i).imgdecor2[1] = SDL_LoadBMP ("data/parbre.bmp");
	(*i).imgdecor2[2] = SDL_LoadBMP ("data/pmer.bmp");
	(*i).imgdecor2[3] = SDL_LoadBMP ("data/pmaison.bmp");
	(*i).imgdecor2[4] = SDL_LoadBMP ("data/rouge.bmp");
	(*i).imgdecor2[5] = SDL_LoadBMP ("data/bleu.bmp");
	(*i).imgdecor2[6] = SDL_LoadBMP ("data/pmontagne.bmp");
	
	(*i).imgunite = (SDL_Surface**) malloc (30*sizeof (SDL_Surface*));
	(*i).imgunite[0] = SDL_LoadBMP ("data/tomr.bmp");
	(*i).imgunite[1] = SDL_LoadBMP ("data/patricr.bmp");
	(*i).imgunite[2] = SDL_LoadBMP ("data/jojor.bmp");
	(*i).imgunite[3] = SDL_LoadBMP ("data/bobir.bmp");
	(*i).imgunite[4] = SDL_LoadBMP ("data/lulur.bmp");
	
	(*i).imgunite[5] = SDL_LoadBMP ("data/tomb.bmp");
	(*i).imgunite[6] = SDL_LoadBMP ("data/patricb.bmp");
	(*i).imgunite[7] = SDL_LoadBMP ("data/jojob.bmp");
	(*i).imgunite[8] = SDL_LoadBMP ("data/bobib.bmp");
	(*i).imgunite[9] = SDL_LoadBMP ("data/lulub.bmp");
	
	
	(*i).imgunite[10] = SDL_LoadBMP ("data/tomRD.bmp");
	(*i).imgunite[11] = SDL_LoadBMP ("data/tomRG.bmp");
	(*i).imgunite[12] = SDL_LoadBMP ("data/patricRD.bmp");
	(*i).imgunite[13] = SDL_LoadBMP ("data/patricRG.bmp");
	(*i).imgunite[14] = SDL_LoadBMP ("data/jojoRD.bmp");
	(*i).imgunite[15] = SDL_LoadBMP ("data/jojoRG.bmp");
	(*i).imgunite[16] = SDL_LoadBMP ("data/bobiRD.bmp");
	(*i).imgunite[17] = SDL_LoadBMP ("data/bobiRG.bmp");
	(*i).imgunite[18] = SDL_LoadBMP ("data/luluRD.bmp");
	(*i).imgunite[19] = SDL_LoadBMP ("data/luluRG.bmp");
	
	(*i).imgunite[20] = SDL_LoadBMP ("data/tomBD.bmp");
	(*i).imgunite[21] = SDL_LoadBMP ("data/tomBG.bmp");
	(*i).imgunite[22] = SDL_LoadBMP ("data/patricBD.bmp");
	(*i).imgunite[23] = SDL_LoadBMP ("data/patricBG.bmp");
	(*i).imgunite[24] = SDL_LoadBMP ("data/jojoBD.bmp");
	(*i).imgunite[25] = SDL_LoadBMP ("data/jojoBG.bmp");
	(*i).imgunite[26] = SDL_LoadBMP ("data/bobiBD.bmp");
	(*i).imgunite[27] = SDL_LoadBMP ("data/bobiBG.bmp");
	(*i).imgunite[28] = SDL_LoadBMP ("data/luluBD.bmp");
	(*i).imgunite[29] = SDL_LoadBMP ("data/luluBG.bmp");
	
	
	(*i).imgcurseur = (SDL_Surface**) malloc (3*sizeof (SDL_Surface*));
	(*i).imgcurseur[0] = SDL_LoadBMP ("data/curseurchoix.bmp");
	(*i).imgcurseur[1] = SDL_LoadBMP ("data/curseurchoix2.bmp");
	(*i).imgcurseur[2] = SDL_LoadBMP ("data/curseur.bmp");
	
	(*i).imgfleche = (SDL_Surface**) malloc (6*sizeof (SDL_Surface*));
	(*i).imgfleche[0] = SDL_LoadBMP ("data/flechegauche.bmp");
	(*i).imgfleche[1] = SDL_LoadBMP ("data/flechebas.bmp");
	(*i).imgfleche[2] = SDL_LoadBMP ("data/flechedroite.bmp");
	(*i).imgfleche[3] = SDL_LoadBMP ("data/flechehaut.bmp");
	(*i).imgfleche[4] = SDL_LoadBMP ("data/barrehorizontale.bmp");
	(*i).imgfleche[5] = SDL_LoadBMP ("data/barreverticale.bmp");
	
	(*i).imgicone = (SDL_Surface**) malloc (16*sizeof (SDL_Surface*));
	(*i).imgicone[0] = SDL_LoadBMP ("data/cabaneicone.bmp");
	(*i).imgicone[1] = SDL_LoadBMP ("data/findetour.bmp");
	(*i).imgicone[2] = SDL_LoadBMP ("data/popupr.bmp");
	(*i).imgicone[3] = SDL_LoadBMP ("data/popupb.bmp");
	(*i).imgicone[4] = SDL_LoadBMP ("data/sauvegarder.bmp");
	(*i).imgicone[5] = SDL_LoadBMP ("data/popup.bmp");
	(*i).imgicone[6] = SDL_LoadBMP ("data/popup2.bmp");
	(*i).imgicone[7] = SDL_LoadBMP ("data/quitter.bmp");
	(*i).imgicone[8] = SDL_LoadBMP ("data/popupsauv.bmp");
	(*i).imgicone[9] = SDL_LoadBMP ("data/plaineicone.bmp");
	(*i).imgicone[10] = SDL_LoadBMP ("data/arbreicone.bmp");
	(*i).imgicone[11] = SDL_LoadBMP ("data/mericone.bmp");
	(*i).imgicone[12] = SDL_LoadBMP ("data/caillouicone.bmp");
	(*i).imgicone[13] = SDL_LoadBMP ("data/popupreinit.bmp");
	(*i).imgicone[14] = SDL_LoadBMP ("data/popupmapsauv.bmp");
	(*i).imgicone[15] = SDL_LoadBMP ("data/popuppassauv.bmp");
	
	(*i).imgusine = (SDL_Surface**) malloc (5*sizeof (SDL_Surface*));
	(*i).imgusine[0] = SDL_LoadBMP ("data/fondusine.bmp");
	(*i).imgusine[1] = SDL_LoadBMP ("data/fondcombat.bmp");
	(*i).imgusine[2] = SDL_LoadBMP ("data/jaugerouge.bmp");
	(*i).imgusine[3] = SDL_LoadBMP ("data/jaugebleu.bmp");
	(*i).imgusine[4] = SDL_LoadBMP ("data/fight.bmp");
	
	(*i).imgmenuprinc = (SDL_Surface**) malloc (15*sizeof (SDL_Surface*));
	(*i).imgmenuprinc[0] = SDL_LoadBMP ("data/menuprinc.bmp");
	(*i).imgmenuprinc[1] = SDL_LoadBMP ("data/menuprinc2.bmp");
	(*i).imgmenuprinc[2] = SDL_LoadBMP ("data/casenn.bmp");
	(*i).imgmenuprinc[3] = SDL_LoadBMP ("data/caseoui.bmp");	
	(*i).imgmenuprinc[4] = SDL_LoadBMP ("data/joueur1.bmp");
	(*i).imgmenuprinc[5] = SDL_LoadBMP ("data/joueur2.bmp");
	(*i).imgmenuprinc[6] = SDL_LoadBMP ("data/fait.bmp");
	(*i).imgmenuprinc[7] = SDL_LoadBMP ("data/optionfond.bmp");
	(*i).imgmenuprinc[8] = SDL_LoadBMP ("data/editeur.bmp");
	(*i).imgmenuprinc[9] = SDL_LoadBMP ("data/url.bmp");
	(*i).imgmenuprinc[10] = SDL_LoadBMP ("data/retour.bmp");
	(*i).imgmenuprinc[11] = SDL_LoadBMP ("data/musique.bmp");
	(*i).imgmenuprinc[12] = SDL_LoadBMP ("data/bruitage.bmp");
	(*i).imgmenuprinc[13] = SDL_LoadBMP ("data/menuprinc3.bmp");
	(*i).imgmenuprinc[14] = SDL_LoadBMP ("data/plus.bmp");
}

void DestructionImage (Image * i)
{
	int j;
	for (j = 0; j < 21; j++)
	{
		SDL_FreeSurface((*i).imgdecor[j]);
	}
	free((*i).imgdecor);
	(*i).imgdecor = NULL;
	for (j = 0; j < 7; j++)
	{
		SDL_FreeSurface((*i).imgdecor2[j]);
	}
	free((*i).imgdecor2);
	(*i).imgdecor2 = NULL;
	for (j = 0; j < 30; j++)
	{
		SDL_FreeSurface((*i).imgunite[j]);
	}
	free((*i).imgunite);
	(*i).imgunite = NULL;
	for (j = 0; j < 3; j++)
	{
		SDL_FreeSurface((*i).imgcurseur[j]);
	}
	free((*i).imgcurseur);
	(*i).imgcurseur = NULL;
	for (j = 0; j < 6; j++)
	{
		SDL_FreeSurface((*i).imgfleche[j]);
	}
	free((*i).imgfleche);
	(*i).imgfleche = NULL;
	for (j = 0; j < 16; j++)
	{
		SDL_FreeSurface((*i).imgicone[j]);
	}
	free((*i).imgicone);
	(*i).imgicone = NULL;
	for (j = 0; j < 5; j++)
	{
		SDL_FreeSurface((*i).imgusine[j]);
	}
	free((*i).imgusine);
	(*i).imgusine = NULL;
	for (j = 0; j < 15; j++)
	{
		SDL_FreeSurface((*i).imgmenuprinc[j]);
	}
	free((*i).imgmenuprinc);
	(*i).imgmenuprinc = NULL;
}

void ImageTestRegression()
{
	Image * itest = (Image*) malloc (sizeof (Image));
	int j;
	
	/* Vérification de la procédure InitialisationImage */
	InitialisationImage(itest);
	
	assert( (*itest).imgdecor != NULL);
	for (j = 0; j < 21; j++)
	{
		assert( (*itest).imgdecor[j] != NULL);
	}
	
	assert( (*itest).imgdecor2 != NULL);
	for (j = 0; j < 7; j++)
	{
		assert( (*itest).imgdecor2[j] != NULL);
	}
	
	assert( (*itest).imgunite != NULL);
	for (j = 0; j < 30; j++)
	{
		assert( (*itest).imgunite[j] != NULL);
	}
	
	assert( (*itest).imgcurseur != NULL);
	for (j = 0; j < 3; j++)
	{
		assert( (*itest).imgcurseur[j] != NULL);
	}
	
	assert( (*itest).imgfleche != NULL);
	for (j = 0; j < 6; j++)
	{
		assert( (*itest).imgfleche[j] != NULL);
	}
	
	assert( (*itest).imgicone != NULL);
	for (j = 0; j < 16; j++)
	{
		assert( (*itest).imgicone[j] != NULL);
	}
	
	assert( (*itest).imgusine != NULL);
	for (j = 0; j < 5; j++)
	{
		assert( (*itest).imgusine[j] != NULL);
	}
	
	assert( (*itest).imgmenuprinc != NULL);
	for (j = 0; j < 15; j++)
	{
		assert( (*itest).imgmenuprinc[j] != NULL);
	}
	
	/* Vérification de la procédure DestructionImage */
	DestructionImage(itest);
	
	assert( (*itest).imgdecor == NULL);
	assert( (*itest).imgdecor2 == NULL);
	assert( (*itest).imgunite == NULL);
	assert( (*itest).imgcurseur == NULL);
	assert( (*itest).imgfleche == NULL);
	assert( (*itest).imgicone == NULL);
	assert( (*itest).imgusine == NULL);
	assert( (*itest).imgmenuprinc == NULL);
	
}